<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>大连飞北京机票分析</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link rel='stylesheet' href='/css/cover.css' />
    <script src="/js/jquery.min.js"></script>
    <!--<script type="text/javascript" src="/javascripts/vue.js"></script>-->
    <script type="text/javascript" src="/js/vue.min.js"></script>
    <script type="text/javascript" src="/js/Chart.js"></script>
</head>
<body>

<div id="vue_block" class="site-wrapper">
    <!--<div class="site-wrapper">-->
        <div class="site-wrapper-inner">

        <div class="cover-container">

            <div class="masthead clearfix">
                <div class="inner">
                    <h3 class="masthead-brand">大连-北京机票分析</h3>
                    <nav>
                        <ul class="nav masthead-nav">
                            <li class="active"><a href="#" @click="home">主页</a></li>
                            <li><a href="#" >关于</a></li>
                        </ul>
                    </nav>
                </div>
            </div>

            <div class="inner cover">
                <div v-if="pagename==='index'">
                    <div v-show="pagetype==='analysis'" style="margin-top:60px;">
                        <canvas id="myChart" width="200" height="50"></canvas>
                        <canvas id="myChart2" width="200" height="50"></canvas>
                        <canvas id="myChart3" width="200" height="50"></canvas>
                        <canvas id="myChart4" width="200" height="50"></canvas>
                        <canvas id="myChart5" width="200" height="50"></canvas>
                        <canvas id="myChart6" width="200" height="50"></canvas>
                    </div>
                    <button class="btn btn-default" @click="spidedata">爬取机票数据</button>
                    <button class="btn btn-default" style="margin-left: 10px" @click="analysis">
                        分析机票数据
                    </button>

                    <div style="margin-top:20px;max-height:600px; overflow:auto;background-color: #a9a9a9;border-radius: 5px;" align="left" class="jumbotron" id="jumb">
                        <div v-show="pagetype==='spider'">
                            <ul v-for="pt in pagetext" style="margin:0px;">
                               {{ pt.text }}
                            </ul>
                        </div>
                        <div v-show="pagetype==='analysis'">
                            <ul v-for="pt in pagetext" style="margin:0px;">
                                {{ pt.text }}
                            </ul>
                        </div>

                    </div>


                </div>
                <div v-else>
                    <p>正在制作</p>
                </div>
            </div>

            <div class="mastfoot">
                <div class="inner">
                    <p>大数据平台应用与开发大作业
                        <span style="display:block;width:50px;"></span>
                        陈宗豪  黄鑫
                    </p>
                </div>
            </div>

        </div>

    <!--</div>-->
    </div>
</div>
<script>
    new Vue({
        el: '#vue_block',
        data: {
            pagename:"index",
            pagetype:"",
            pagetext:[{text:""}]
        },
        methods:{
            home:function(){
                this.pagename="index";
//                alert("123");
            },
            display:function(){
                console.log(this.pagetext);
            },
            analysis:function(){
                var _this=this;
                this.pagetype="analysis";
                $.ajax({
                    url:"/spide/analyflight",
                    type:"get",
                    contentType:"application/json;charset=utf-8",
                    success:function(text){
                        this.pagetext=text;
                    }
                })
                var timer=window.setInterval(function(){
                    var jumb=document.getElementById("jumb");
                    jumb.scrollTop=jumb.scrollHeight;

                    $.ajax({
                        url:"/spide/analyinfo",
                        type:"post",
                        contentType:"application/json;charset=utf-8",
                        success:function(text){
                            _this.pagetext=text;
                            if(times++>3){
                                window.clearInterval(timer);
//                                console.log(text[1]);
                                var label=[];
                                var data=[];
                                var cor=[];
                                for(var i=1;i<text.length;i++){
                                    var tempDate=JSON.parse(text[i].text).departureDate;
                                    var tempCor=JSON.parse(text[i].text).arlineCompanyShortName;
                                    var tempPrice=JSON.parse(text[i].text).priceBase;
                                    if(!data[tempCor]){
                                        data[tempCor]=[];
                                        label[tempCor]=[];
                                        cor[cor.length]=tempCor;
                                    }

                                    var tempdata=data[tempCor];
                                    tempdata[tempdata.length]=tempPrice;

                                    var templabel=label[tempCor];
                                    templabel[templabel.length]=JSON.parse(text[i].text).departureDate.substring(0,10)
//                                    if (tempDate!==label[label.length-1]){
//                                        label[label.length]=JSON.parse(text[i].text).departureDate;
//                                    }
                                }
//                                for(var i in label){
//                                    label[i]=label[i].substring(0,10);
//                                }
                                console.log(data[cor[0]]);
//                                console.log(label);
                                new Chart(ctx,{
                                    type: 'line',
                                    data: {
                                        labels: label[cor[0]],
                                        datasets: [{
                                            label: cor[0],
                                            data: data[cor[0]],
                                            backgroundColor: [
                                                'rgba(255, 99, 132, 0.2)',
                                            ],
                                            borderColor: [
                                                'rgba(255,99,132,1)',
                                            ],
                                            borderWidth: 1
                                        }]
                                    },
                                    options: {
                                        scales: {
                                            yAxes: [{
                                                ticks: {
                                                    beginAtZero:true
                                                }
                                            }]
                                        }
                                    }
                                });
                                new Chart(ctx2,{
                                    type: 'line',
                                    data: {
                                        labels: label[cor[1]],
                                        datasets: [{
                                            label: cor[1],
                                            data: data[cor[1]],
                                            backgroundColor: [
                                                'rgba(255, 99, 132, 0.2)',
                                            ],
                                            borderColor: [
                                                'rgba(255,99,132,1)',
                                            ],
                                            borderWidth: 1
                                        }]
                                    },
                                    options: {
                                        scales: {
                                            yAxes: [{
                                                ticks: {
                                                    beginAtZero:true
                                                }
                                            }]
                                        }
                                    }
                                });
                                new Chart(ctx3,{
                                    type: 'line',
                                    data: {
                                        labels: label[cor[2]],
                                        datasets: [{
                                            label: cor[2],
                                            data: data[cor[2]],
                                            backgroundColor: [
                                                'rgba(255, 99, 132, 0.2)',
                                            ],
                                            borderColor: [
                                                'rgba(255,99,132,1)',
                                            ],
                                            borderWidth: 1
                                        }]
                                    },
                                    options: {
                                        scales: {
                                            yAxes: [{
                                                ticks: {
                                                    beginAtZero:true
                                                }
                                            }]
                                        }
                                    }
                                });
                                new Chart(ctx4,{
                                    type: 'line',
                                    data: {
                                        labels: label[cor[3]],
                                        datasets: [{
                                            label: cor[3],
                                            data: data[cor[3]],
                                            backgroundColor: [
                                                'rgba(255, 99, 132, 0.2)',
                                            ],
                                            borderColor: [
                                                'rgba(255,99,132,1)',
                                            ],
                                            borderWidth: 1
                                        }]
                                    },
                                    options: {
                                        scales: {
                                            yAxes: [{
                                                ticks: {
                                                    beginAtZero:true
                                                }
                                            }]
                                        }
                                    }
                                });
                                new Chart(ctx5,{
                                    type: 'line',
                                    data: {
                                        labels: label[cor[4]],
                                        datasets: [{
                                            label: cor[4],
                                            data: data[cor[4]],
                                            backgroundColor: [
                                                'rgba(255, 99, 132, 0.2)',
                                            ],
                                            borderColor: [
                                                'rgba(255,99,132,1)',
                                            ],
                                            borderWidth: 1
                                        }]
                                    },
                                    options: {
                                        scales: {
                                            yAxes: [{
                                                ticks: {
                                                    beginAtZero:true
                                                }
                                            }]
                                        }
                                    }
                                });
                                new Chart(ctx6,{
                                    type: 'line',
                                    data: {
                                        labels: label[cor[5]],
                                        datasets: [{
                                            label: cor[5],
                                            data: data[cor[5]],
                                            backgroundColor: [
                                                'rgba(255, 99, 132, 0.2)',
                                            ],
                                            borderColor: [
                                                'rgba(255,99,132,1)',
                                            ],
                                            borderWidth: 1
                                        }]
                                    },
                                    options: {
                                        scales: {
                                            yAxes: [{
                                                ticks: {
                                                    beginAtZero:true
                                                }
                                            }]
                                        }
                                    }
                                });
                            }
                        }
                    })},200);

            },
            spidedata:function(){
                var _this=this;
                this.pagetype="spider";
                $.ajax({
                    url:"/spide/spideflight",
                    type:"get",
                    contentType:"application/json;charset=utf-8",
                    success:function(text){
                        this.pagetext=text;
                    }
                })
                var timer=window.setInterval(function(){
                    var jumb=document.getElementById("jumb");
                    jumb.scrollTop=jumb.scrollHeight;

                    $.ajax({
                        url:"/spide/spideinfo",
                        type:"post",
                        contentType:"application/json;charset=utf-8",
                        success:function(text){
                            _this.pagetext=text;
                            if(times++>100){
                                window.clearInterval(timer);

                            }
                        }
                    })},500);

            }
        }
    });
    var times=0;

    var ctx = $("#myChart").get(0).getContext("2d");
    var ctx2 = $("#myChart2").get(0).getContext("2d");
    var ctx3 = $("#myChart3").get(0).getContext("2d");
    var ctx4 = $("#myChart4").get(0).getContext("2d");
    var ctx5 = $("#myChart5").get(0).getContext("2d");
    var ctx6 = $("#myChart6").get(0).getContext("2d");

</script>
</body>
</html>